// 富文本
<template>
  <el-card>
    <div class="quill-editor-example">
      <!-- quill-editor -->
      <quill-editor
        ref="myTextEditor"
        v-model="content"
        :options="editorOption"
        @blur="onEditorBlur($event)"
        @focus="onEditorFocus($event)"
        @ready="onEditorReady($event)"
      ></quill-editor>
      <div class="quill-code">
        <code class="hljs" v-html="contentCode"></code>
      </div>
    </div>
  </el-card>
</template>

<script>
import hljs from 'highlight.js'
export default {
  data() {
    return {
      name: '01-example',
      content: `<h2 class="ql-align-center"><span class="ql-font-serif">Text content loading..</span></h2>`,
      editorOption: {
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ 'header': 1 }, { 'header': 2 }],
            [{ 'list': 'ordered' }, { 'list': 'bullet' }],
            [{ 'script': 'sub' }, { 'script': 'super' }],
            [{ 'indent': '-1' }, { 'indent': '+1' }],
            [{ 'direction': 'rtl' }],
            [{ 'size': ['small', false, 'large', 'huge'] }],
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
            [{ 'font': [] }],
            [{ 'color': [] }, { 'background': [] }],
            [{ 'align': [] }],
            ['clean'],
            ['link', 'image', 'video']
          ],
          syntax: {
            highlight: text => hljs.highlightAuto(text).value
          }
        }
      }
    }
  },
  methods: {
    onEditorBlur(editor) {
      // console.log('editor blur!', editor)
    },
    onEditorFocus(editor) {
      // console.log('editor focus!', editor)
    },
    onEditorReady(editor) {
      // console.log('editor ready!', editor)
    }
  },
  computed: {
    editor() {
      return this.$refs.myTextEditor.quill
    },
    contentCode() {
      return hljs.highlightAuto(this.content).value
    }
  },
  mounted() {
    console.log('this is my editor', this.editor)
    setTimeout(() => {
      this.content = `
      <h3><a href="http://www.baidu.com/link?url=XoB4VMR28ITqFIAOnfjAes-Gy0MRBVvbdAYb2lMaU5DG2290BdnK-qj5Dr4cKQLUNhc3HU4y3MpiNP3lcpeZkxA5YcL5C37yOiEwhCR8Rmi" target="_blank">什么是</a><a href="http://www.baidu.com/link?url=XoB4VMR28ITqFIAOnfjAes-Gy0MRBVvbdAYb2lMaU5DG2290BdnK-qj5Dr4cKQLUNhc3HU4y3MpiNP3lcpeZkxA5YcL5C37yOiEwhCR8Rmi" target="_blank" style="color: rgb(204, 0, 0);">ES6</a><a href="http://www.baidu.com/link?url=XoB4VMR28ITqFIAOnfjAes-Gy0MRBVvbdAYb2lMaU5DG2290BdnK-qj5Dr4cKQLUNhc3HU4y3MpiNP3lcpeZkxA5YcL5C37yOiEwhCR8Rmi" target="_blank">? - CSDN博客</a></h3><p><a href="http://www.baidu.com/link?url=XoB4VMR28ITqFIAOnfjAes-Gy0MRBVvbdAYb2lMaU5DG2290BdnK-qj5Dr4cKQLUNhc3HU4y3MpiNP3lcpeZkxA5YcL5C37yOiEwhCR8Rmi" target="_blank"><img src="https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2571458027,1313469084&amp;fm=85&amp;app=63&amp;f=JPEG?w=120&amp;h=75&amp;s=42943D8ED48949E1147EAA7E0300C076"></a></p>
                        `
    }, 1000)
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 30px;
  .quill-code {
    border: none;
    height: auto;
    overflow-y: auto;
    > code {
      width: 100%;
      margin: 0;
      padding: 1rem;
      border: 1px solid #ccc;
      border-top: none;
      border-radius: 0;
      height: 10rem;
      overflow-y: auto;
      resize: vertical;
    }
  }
}
</style>